
//var host="";
var host="http://192.168.0.249:8686";

// var host="";

function httpHelperget(url, callback){


    url = host+url;

    var token = sessionStorage.getItem("token");

    var userinfo = localStorage.getItem("userinfo");
    if (userinfo != null) {
        var value = JSON.parse(userinfo);
        // token = value.token;
    }

    var xhr = new XMLHttpRequest();
    xhr.open("GET", url);
    xhr.setRequestHeader("Access-Control-Allow-Origin","*");
    xhr.setRequestHeader("Content-Type","application/json;charset=UTF-8");  
    xhr.setRequestHeader("Authorization", 'Bearer ' + token);
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
            var httpStatus = xhr.responseText;
            callback(true, xhr);
        }else if (xhr.readyState == 4 && xhr.status == 226){
        	
        }else{
        	
        }
    };
    xhr.send();

};

//post
function httpHelperpost(url,params,callback){  

    url = host+url;

    var token = sessionStorage.getItem("token");
    var userinfo = localStorage.getItem("userinfo");
    if (userinfo != null) {
        var value = JSON.parse(userinfo);
        //token = value.token;
    }

    var xhr = new XMLHttpRequest();
    xhr.open("POST", url);  
    xhr.setRequestHeader("Content-Type","application/json;charset=UTF-8");  
    xhr.setRequestHeader("Access-Control-Allow-Origin","*");
    xhr.setRequestHeader("Authorization", 'Bearer ' + token);
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
            var httpStatus = xhr.responseText;
            callback(true, xhr);
        }else if (xhr.readyState == 4 && xhr.status == 226){
        }else{
        }
    };
    xhr.send(params);
}  



    //post
 function httpHelperput(url,params,callback){  

    url = host+url;


     var token = sessionStorage.getItem("token");
     var userinfo = localStorage.getItem("userinfo");
     if (userinfo != null) {
         var value = JSON.parse(userinfo);
         //token = value.token;
     }



    var xhr = new XMLHttpRequest();
    xhr.open("PUT", url);  
    xhr.setRequestHeader("Content-Type","application/json;charset=UTF-8");  
    xhr.setRequestHeader("Access-Control-Allow-Origin","*");
     xhr.setRequestHeader("Authorization", 'Bearer ' + token);
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
            var httpStatus = xhr.responseText;
            callback(true, xhr);
        }else if (xhr.readyState == 4 && xhr.status == 226){
        }else if (xhr.readyState == 4 && xhr.status == 417){
        }else{
        }
    };
    xhr.send(params);

    }  

 //    httpHelperpost("http://127.0.0.1:3000/test","id=1&ids=2", function(err,data){  
 // if(err){  
 // //错误处理  
 // }else{  
 // cc.log(data);  
 // }  
 // }) 